<template>
  <h1>EL-表格组件</h1>
  <el-table
    :data="tableData"
    style="width: 500px;margin: 0 auto;">
    <el-table-column
      prop="date"
      label="日期"
      width="180"/>
    <el-table-column
      prop="name"
      label="姓名"
      width="180"/>
    <el-table-column
      prop="address"
      label="地址"/>
  </el-table>
  <el-table :data="arr" style="width: 500px;margin: 0 auto;">
    <el-table-column label="编号" type="index" width="80" align="center"/>
    <el-table-column prop="name" label="姓名" align="center"/>
    <el-table-column prop="salary" label="工资" align="center"/>
    <el-table-column prop="job" label="职位" align="center">
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import {ref} from "vue";
const tableData = ref([
  {
    date: '2016-05-02',
    name: '王小虎',
    address: '上海市普陀区金沙江路 1518 弄'
  },
  {
    date: '2016-05-04',
    name: '王小虎',
    address: '上海市普陀区金沙江路 1517 弄'
  },
  {
    date: '2016-05-01',
    name: '王小虎',
    address: '上海市普陀区金沙江路 1519 弄'
  },
  {
    date: '2016-05-03',
    name: '王小虎',
    address: '上海市普陀区金沙江路 1516 弄'
  }
])
//定义数组用来保存多个员工数据
const arr = ref([
  {name: "张三", salary: 3000, job: "销售员"},
  {name: "李四", salary: 5000, job: "饲养员"},
  {name: "王五", salary: 8000, job: "护林员"},
  {name: "赵六", salary: 10000, job: "程序员"}
]);
const del = (index,emp) => {
  if (confirm("确定要删除"+ emp.name+"吗？")) {
    arr.value.splice(index, 1);
  }
}
</script>


<style scoped>

</style>
